import absSubAction from "../abssubcmdaction";
import globalConst from "../../../canvas/common/globalConst.js";
var global = globalConst.GlobalConst;
import {LGXEnums}  from "../../../canvas/common/sysenum";

import cmdenums from "../cmdenums";

class EllipseDrawAction extends absSubAction.AbsSubAction {
    constructor() {
        super();
        this.mainCMD = cmdenums.DrawCmdType.ellipse;
    }

    actCMD(type, val, mainctl) {
        let actRst = null;
        let nextTips = "";
        type = type.toUpperCase();
        if (type == 'ELLIPSE') {
            let toolKind = global.BaseUnitEllipse;
            toolKind = toolKind << 16;
            mainctl.setCMDTool(toolKind);
            nextTips = "输入圆心坐标或在图中鼠标左键点击确定坐标:x,y";
            let cmd = { type: 'c', value: "" };
            actRst = { cmdObj: cmd, nextTips, appendToPreCMD:"", finish: false };
        }
        else {
            actRst = this.act2InPlottingCMD(type,mainctl);
        }
        return actRst;
    }

    actCanvasEvt(evt, mainctl) {
        let actRst = null;
        if (evt.eventKind == LGXEnums.LGXEventKind.FinishDraw) {
            let coordDecs = evt.wx.toFixed(2) + "," + evt.wy.toFixed(2);
            let cmd = new absSubAction.TCmd();
            cmd.type = 'draw_lmousedown';
            cmd.value = coordDecs;
            let appendToPreCMD = coordDecs;
            actRst = { cmdObj: cmd, nextTips:"", appendToPreCMD,finish:true };
        }
        else if (evt.mouseDownTime == 1) {
            let coordDecs = evt.wx.toFixed(2) + "," + evt.wy.toFixed(2);
            let cmd = new absSubAction.TCmd();
            cmd.type = 'draw_lmousedown';
            cmd.value = coordDecs;
            let nextTips = "输入长轴半径值或输入第二个点坐标或在图中鼠标左键点击确定长轴半径:x,y,相对坐标使用:@x,y。使用当前位置直接回车（e）";
            let appendToPreCMD = coordDecs;
            actRst = { cmdObj: cmd, nextTips, appendToPreCMD };
        }
        else if (evt.mouseDownTime == 2) {
            let coordDecs = evt.wx.toFixed(2) + "," + evt.wy.toFixed(2);
            let cmd = new absSubAction.TCmd();
            cmd.type = 'draw_lmousedown';
            cmd.value = coordDecs;
            let nextTips = "输入短轴半径值或输入第三个点坐标或在图中鼠标左键点击确定短轴半径:x,y,相对坐标使用:@x,y。使用当前位置直接回车（e）";
            let appendToPreCMD = coordDecs;
            actRst = { cmdObj: cmd, nextTips, appendToPreCMD };
        }
        return actRst;
    }
}

export default { EllipseDrawAction }